#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e5+10;

int n,m,ans;

struct line{int l,r;}q[N];

bool operator < (line a,line b){return a.l ^ b.l ? a.l < b.l : a.r < b.r;}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= n;i++) q[i].l = in,q[i].r = in;
	sort(q+1,q+n+1); multiset<int> t;
	for(int i = 1;i <= n;i++){
		while(t.size() && *(t.begin()) < q[i].l) m++, t.erase(t.begin());
		if(m) t.insert(q[i].r-1),m--;
		else {
			if(t.size() && *(--t.end()) > q[i].r-1) t.erase(--t.end()),t.insert(q[i].r-1);
			ans++;
		}
	}printf("%d\n",ans);
	return 0;
}
